package com.datn.utils;


import com.google.android.maps.GeoPoint;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class GPSCustom 
{
	private LocationManager myLocationManager;//
	private LocationListener myLocationListener;
	private Location initLocation;
	private GeoPoint GeoPoint_GPS;
	
	public GPSCustom(Context mContext)
	{
		 myLocationManager = (LocationManager)mContext.getSystemService(Context.LOCATION_SERVICE);
	     myLocationListener = new MyLocationListener();
	     myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myLocationListener);
		 initLocation=myLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		 
		 if(initLocation!=null)
		    {
			 //get location
	    	 myLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,myLocationListener);
	          
	          GeoPoint_GPS = new GeoPoint(
				        (int)(initLocation.getLatitude()*1E6),
				        (int)(initLocation.getLongitude()*1E6));
		    }
		
	  }
	    
		
	
//---------------------------------------------------------------------------	
	public GeoPoint getCurrentLocation()
	{
		return GeoPoint_GPS;
		
	}
//----------------------------------------------------------------------------	
//Update Location 	
	class MyLocationListener implements LocationListener 
	{

		public void onLocationChanged(Location location) 
		{
			 GeoPoint_GPS = new GeoPoint(
				        (int)(location.getLatitude()*1E6),
				        (int)(location.getLongitude()*1E6));
				 
			 
		}

		public void onProviderDisabled(String arg0)
		{
			// TODO Auto-generated method stub

		}

		public void onProviderEnabled(String arg0)
		{
			// TODO Auto-generated method stub
			
		}

		public void onStatusChanged(String arg0, int arg1, Bundle arg2) 
		{
			// TODO Auto-generated method stub

		}

	}
//-------------------------------------------------------------------------------	
}
